import { http } from "@/utils/http";
import type { HttpResult } from "@/utils/http/types";

export async function queryUserTable(params) {
  return http.request<HttpResult>("get", "/admin/sysuser/get/table", {
    params: params
  });
}

export function queryUser(id) {
  return http.request<HttpResult>("get", `/admin/sysuser/get/${id}`);
}

export function getUserByName(params) {
  return http.request<HttpResult>("get", "/admin/sysuser/get", {
    params: params
  });
}

export async function addUser(params) {
  return http.request<HttpResult>("post", "/admin/sysuser/insert", {
    data: params
  });
}

export async function updateUser(params) {
  return http.request<HttpResult>("post", "/admin/sysuser/update", {
    data: params
  });
}

/**
 * @param {*} params
 * @returns
 */
export async function updateUserPassword(params) {
  const data = {
    id: params.user_id,
    oldPwd: params.oldPwd,
    newPwd: params.newPwd
  };
  return http.request<HttpResult>("post", "/admin/sysuser/update/pwd", {
    data: data
  });
}

/**
 *
 * @param {*} params
 * @returns
 */
export async function updateResetPassword(params) {
  const data = {
    id: params.id,
    password: params.password
  };
  return http.request<HttpResult>("post", "/admin/sysuser/update/resetpwd", {
    data: data
  });
}

export function deleteUser(ids) {
  return http.request<HttpResult>("post", `/admin/sysuser/delete/${ids}`);
}

export async function lockUser(params) {
  return http.request<HttpResult>("post", "/admin/sysuser/update/lock", {
    data: params
  });
}

export async function unLockUser(params) {
  return http.request<HttpResult>("post", "/admin/sysuser/update/unlock", {
    data: params
  });
}

export function validUserCode(params) {
  return http.request<HttpResult>("get", "/admin/sysuser/get/check/code", {
    params: { id: params.id, userCode: params.userCode }
  });
}
